# !/usr/bin/env python
# -*-coding:utf-8 -*-
"""
@Author : Ayao
@Time   : 2022/5/20
@File   : 旋转矩阵.py
"""

# https://leetcode.cn/leetbook/read/array-and-string/clpgd/
from pprint import pprint
from typing import List


class Solution:
    def rotate(self, matrix: List[List[int]]) -> None:
        """
        Do not return anything, modify matrix in-place instead.
        """
        lens = len(matrix)
        # 对角翻转
        for y in range(lens):
            for x in range(y, lens):
                matrix[x][y], matrix[y][x] = matrix[y][x], matrix[x][y]
        # 垂直中心线翻转
        for y in range(lens):
            for x in range(lens // 2):
                matrix[y][x], matrix[y][lens - x - 1] = matrix[y][lens - x - 1], matrix[y][x]


if __name__ == '__main__':
    matrix = [
        [5, 1, 9, 11],
        [2, 4, 8, 10],
        [13, 3, 6, 7],
        [15, 14, 12, 16]
    ]

    Solution().rotate(matrix)
    pprint(matrix)

    # 对角翻转
    s = [[5, 2, 13, 15],
         [1, 4, 3, 14],
         [9, 8, 6, 12],
         [11, 10, 7, 16]]

    # 垂直中心线翻转
    a = [[15, 13, 2, 5],
         [14, 3, 4, 1],
         [12, 6, 8, 9],
         [16, 7, 10, 11]]
